package net.pinnoocle.playweb.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.aop.PassToken;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.*;
import net.pinnoocle.playdao.entity.web.QrCodeVo;
import net.pinnoocle.playdao.entity.web.user.UserScriptListPageVo;
import net.pinnoocle.playservice.service.impl.ScriptServiceImpl;
import net.pinnoocle.playservice.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ye
 * @Description
 * @create 2021-10-26 14:55
 */
@RestController
@RequestMapping("/script")
@Api(tags = "剧本相关")
public class ScriptController {

    @Autowired
    ScriptServiceImpl scriptService;
    @Autowired
    UserServiceImpl userService;

    @GetMapping("myPlayScripts")
    @ApiOperation("我玩过的本")
    public BaseResult<PageModel<UserScriptListPageVo>> myScripts(@RequestParam("page") Integer page,
                                                                 @RequestParam("pageSize") Integer pageSize){
        String userId = userService.getUserId();
        return new BaseResult<PageModel<UserScriptListPageVo>>().ok(userService.myScripts(userId,page,pageSize,0));
    }

    @GetMapping("myWantPlayScripts")
    @ApiOperation("我想玩的本")
    public BaseResult<PageModel<UserScriptListPageVo>> myWantPlayScripts(@RequestParam("page") Integer page,
                                                                 @RequestParam("pageSize") Integer pageSize){
        String userId = userService.getUserId();
        return new BaseResult<PageModel<UserScriptListPageVo>>().ok(userService.myScripts(userId,page,pageSize,1));
    }

    @GetMapping("topScript")
    @ApiOperation("剧本排行（排序类型传5）")
    @PassToken
    public BaseResult<PageModel<ScriptListVo>> topScript(ScriptListSearchParams params){
        params.setIsDisable(0);
        return new BaseResult<PageModel<ScriptListVo>>().ok(scriptService.scriptList(params));
    }

    @GetMapping("scriptPoster")
    @ApiOperation("剧本海报")
    @PassToken
    public BaseResult<QrCodeVo> scriptPoster(@RequestParam("scriptId") String scriptId){
        return new BaseResult<QrCodeVo>().ok(scriptService.scriptPoster(scriptId));
    }

    @GetMapping("scriptUpAndDown")
    @ApiOperation("剧本上下架 isDisable：0 上架 1 下架")
    public BaseResult<String> scriptUpAndDown(@RequestParam(name = "scriptId") String scriptId,
                                              @RequestParam(name = "isDisable") Integer isDisable){
        boolean result = scriptService.scriptUpAndDown(scriptId,isDisable);
        if(result){
            return new BaseResult<String>().success("剧本"+(isDisable == 0 ? "上架" : "下架")+"成功");
        }
        return new BaseResult<String>().error("剧本"+(isDisable == 0 ? "上架" : "下架")+"失败");
    }

    @GetMapping("deleteScript")
    @ApiOperation("剧本删除")
    public BaseResult<String> deleteScript(@RequestParam(name = "scriptId") String scriptId){
        boolean result = scriptService.deleteScript(scriptId);
        if(result){
            return new BaseResult<String>().success("编辑删除成功");
        }
        return new BaseResult<String>().error("编辑删除失败");
    }
}
